home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
343_01
/
cips3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-08
|
15KB
|
513 lines
/***********************************************
*
* file d:\cips\addsub.c
*
* Functions: This file contains
* add_image_array
* subtract_image_array
*
* Purpose:
* These functions implement
* image addition and subtraction.
*
* External Calls:
* wtiff.c - does_not_exist
* round_off_image_size
* create_allocate_tiff_file
* write_array_into_tiff_image
* tiff.c - read_tiff_header
* rtiff.c - read_tiff_image
*
*
* Modifications:
* 1 April 1992 - created
*
*************************************************/
#include "d:\cips\cips.h"
/*******************************************
*
* add_image_array(...
*
* This function adds two ROWSxCOLS image
* sections. The image file named out_name
* will receive the sum of the image file
* named in1_name and the image file
* named in2_name.
*
*******************************************/
add_image_array(in1_name, in2_name, out_name, the_image, out_image,
il1, ie1, ll1, le1,
il2, ie2, ll2, le2,
il3, ie3, ll3, le3)
char in1_name[], in2_name[], out_name[];
int il1, ie1, ll1, le1,
il2, ie2, ll2, le2,
il3, ie3, ll3, le3;
short the_image[ROWS][COLS],
out_image[ROWS][COLS];
{
int i, j, length, max, width;
struct tiff_header_struct image_header;
if(does_not_exist(out_name)){
printf("\n\n output file does not exist %s", out_name);
read_tiff_header(in1_name, &image_header);
round_off_image_size(&image_header,
&length, &width);
image_header.image_length = length*ROWS;
image_header.image_width = width*COLS;
create_allocate_tiff_file(out_name, &image_header,
out_image);
} /* ends if does_not_exist */
read_tiff_header(in1_name, &image_header);
max = 255;
if(image_header.bits_per_pixel == 4)
max = 16;
read_tiff_image(in1_name, the_image, il1, ie1, ll1, le1);
read_tiff_image(in2_name, out_image, il2, ie2, ll2, le2);
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
out_image[i][j] = the_image[i][j] + out_image[i][j];
if(out_image[i][j] > max)
out_image[i][j] = max;
} /* ends loop over j */
} /* ends loop over i */
write_array_into_tiff_image(out_name, out_image,
il3, ie3, ll3, le3);
} /* ends add_image_array */
/*******************************************
*
* subtract_image_array(...
*
* This function subtracts two ROWSxCOLS image
* sections. The image file named out_name
* will receive the difference of the image file
* named in1_name and the image file
* named in2_name.
*
* out_name = in1_name - in2_name
*
*******************************************/
subtract_image_array(in1_name, in2_name, out_name, the_image, out_image,
il1, ie1, ll1, le1,
il2, ie2, ll2, le2,
il3, ie3, ll3, le3)
char in1_name[], in2_name[], out_name[];
int il1, ie1, ll1, le1,
il2, ie2, ll2, le2,
il3, ie3, ll3, le3;
short the_image[ROWS][COLS],
out_image[ROWS][COLS];
{
int i, j, length, width;
struct tiff_header_struct image_header;
if(does_not_exist(out_name)){
printf("\n\n output file does not exist %s", out_name);
read_tiff_header(in1_name, &image_header);
round_off_image_size(&image_header,
&length, &width);
image_header.image_length = length*ROWS;
image_header.image_width = width*COLS;
create_allocate_tiff_file(out_name, &image_header,
out_image);
} /* ends if does_not_exist */
read_tiff_header(in1_name, &image_header);
read_tiff_image(in1_name, the_image, il1, ie1, ll1, le1);
read_tiff_image(in2_name, out_image, il2, ie2, ll2, le2);
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
out_image[i][j] = the_image[i][j] - out_image[i][j];
if(out_image[i][j] < 0)
out_image[i][j] = 0;
} /* ends loop over j */
} /* ends loop over i */
write_array_into_tiff_image(out_name, out_image,
il3, ie3, ll3, le3);
} /* ends subtract_image_array */
/***********************************************
*
* file d:\cips\cutp.c
*
* Functions: This file contains
* cut_image_piece
* paste_image_piece
* check_cut_and_paste_limits
*
* Purpose:
* These functions cut pieces out
* of images and paste them back into
* images.
*
* External Calls:
* wtiff.c - does_not_exist
* round_off_image_size
* create_allocate_tiff_file
* write_array_into_tiff_image
* tiff.c - read_tiff_header
* rtiff.c - read_tiff_image
*
*
* Modifications:
* 3 April 1992 - created
*
*************************************************/
/*******************************************
*
* cut_image_piece(...
*
* This function cuts out a rectangular
* piece of an image. This rectangle can
* be any shape so long as no dimension
* is greater than ROWS or COLS.
*
*******************************************/
cut_image_piece(name, the_image, il, ie, ll, le)
char name[];
int il, ie, ll, le;
short the_image[ROWS][COLS];
{
if(does_not_exist(name)){
printf("\n\ncut_image_piece>> ERROR "
"image file does not exist %s", name);
return(-1);
} /* ends if does_not_exist */
read_tiff_image(name, the_image, il, ie, ll, le);
} /* ends cut_image_piece */
/*******************************************
*
* paste_image_piece(...
*
* This function pastes a rectangular
* piece of an image into another image.
* This rectangle can be any shape so long
* as no dimension is greater than ROWS or COLS.
* The rectangle to be pasted into the image
* is described by the il, ie, ll, le
* parameters.
*
* You pass is the out_image array just in
* case you need to allocate the destination
* image.
*
*******************************************/
paste_image_piece(dest_name, source_name, the_image,
out_image, il, ie, ll, le)
char dest_name[], source_name[];
int il, ie, ll, le;
short the_image[ROWS][COLS],
out_image[ROWS][COLS];
{
struct tiff_header_struct image_header;
if(does_not_exist(dest_name)){
printf("\n\ncut_image_piece>> "
"image file does not exist %s", dest_name);
read_tiff_header(source_name, &image_header);
create_allocate_tiff_file(dest_name, &image_header,
out_image);
} /* ends if does_not_exist */
write_array_into_tiff_image(dest_name, the_image,
il, ie, ll, le);
} /* ends paste_image_piece */
/*******************************************
*
* check_cut_and_paste_limits(...
*
* This function looks at the line and
* element parameters and ensures that they
* are not bigger than ROWS and COLS. If
* they are bigger, the last element or